package com.glory.erp.invoice.supplier.action;

import java.util.List;

import com.glory.erp.invoice.supplier.service.SupplierService;
import com.glory.erp.invoice.supplier.bean.Supplier;
import com.glory.erp.invoice.supplier.bean.SupplierQuery;
import com.glory.erp.auth.base.BaseAction;

public class SupplierAction extends BaseAction{
	
	public Supplier supplier = new Supplier();
	public SupplierQuery supplierQuery = new SupplierQuery();

	private SupplierService supplierService;
	
	public void setSupplierService(SupplierService supplierService) {
		this.supplierService = supplierService;
	}

	//列表
	public String list(){
		setDataTotal(supplierService.getCount(supplierQuery));
		List<Supplier> supplierList = supplierService.findAll(supplierQuery,pageNum,pageCount);
		put("supplierList", supplierList);
		return LIST;
	}

	//到添加
	public String addView(){
		if(supplier.getUuid()!=null){
			supplier = supplierService.findById(supplier.getUuid());
		}
		return ADD;
	}

	//添加
	public String saveAndUpdate(){
		if(supplier.getUuid() == null){
			supplierService.save(supplier);
		}else{
			supplierService.update(supplier);
		}
		return TO_LIST;
	}

	//删除
	public String delete(){
		supplierService.delete(supplier);
		return TO_LIST;
	}
}